package com.yk.airline.model;

import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Collection;

/**
 * Project Name:airlinecrawler
 * File Name:AirLineModel
 * Package Name:com.yk.airline.model
 * Date:2018/2/1 17:47
 * Author:zhangshaoyang
 * Description:
 * Copyright (c) 2018, 重庆云凯科技有限公司 All Rights Reserved.
 */
@Entity
@Table(name = "air_line", schema = "cykspider", catalog = "")
public class AirLineModel {
    private String id;
    private Timestamp createTime;
    private Timestamp updateTime;
    private CityModel cityByOriginPlace;
    private CityModel cityByArrivePlace;
    private Collection<OriginDataModel> originDataById;

    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "uuid")
    @Id
    @Column(name = "id", nullable = false, length = 255)
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Basic
    @Column(name = "create_time", nullable = true)
    public Timestamp getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Timestamp createTime) {
        this.createTime = createTime;
    }

    @Basic
    @Column(name = "update_time", nullable = true)
    public Timestamp getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Timestamp updateTime) {
        this.updateTime = updateTime;
    }


    @ManyToOne
    @JoinColumn(name = "origin_place", referencedColumnName = "id")
    public CityModel getCityByOriginPlace() {
        return cityByOriginPlace;
    }

    public void setCityByOriginPlace(CityModel cityByOriginPlace) {
        this.cityByOriginPlace = cityByOriginPlace;
    }


    @ManyToOne
    @JoinColumn(name = "arrive_place", referencedColumnName = "id")
    public CityModel getCityByArrivePlace() {
        return cityByArrivePlace;
    }

    public void setCityByArrivePlace(CityModel cityByArrivePlace) {
        this.cityByArrivePlace = cityByArrivePlace;
    }

    @OneToMany(mappedBy = "airLineByAirLine")
    public Collection<OriginDataModel> getOriginDataById() {
        return originDataById;
    }

    public void setOriginDataById(Collection<OriginDataModel> originDataById) {
        this.originDataById = originDataById;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        AirLineModel that = (AirLineModel) o;

        if (id != null ? !id.equals(that.id) : that.id != null) return false;
        if (createTime != null ? !createTime.equals(that.createTime) : that.createTime != null) return false;
        if (updateTime != null ? !updateTime.equals(that.updateTime) : that.updateTime != null) return false;
        if (cityByOriginPlace != null ? !cityByOriginPlace.equals(that.cityByOriginPlace) : that.cityByOriginPlace != null)
            return false;
        if (cityByArrivePlace != null ? !cityByArrivePlace.equals(that.cityByArrivePlace) : that.cityByArrivePlace != null)
            return false;
        return originDataById != null ? originDataById.equals(that.originDataById) : that.originDataById == null;
    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + (createTime != null ? createTime.hashCode() : 0);
        result = 31 * result + (updateTime != null ? updateTime.hashCode() : 0);
        result = 31 * result + (cityByOriginPlace != null ? cityByOriginPlace.hashCode() : 0);
        result = 31 * result + (cityByArrivePlace != null ? cityByArrivePlace.hashCode() : 0);
        result = 31 * result + (originDataById != null ? originDataById.hashCode() : 0);
        return result;
    }
}
